package com.liukai.todo_android.ui.dialog;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.liukai.todo_android.R;
import com.liukai.todo_android.call_back.IUpdateScheduleCallBack;
import com.liukai.todo_android.entity.ItemVo;
import com.liukai.todo_android.entity.Resp;
import com.liukai.todo_android.entity.vo.UpdateItemVo;
import com.liukai.todo_android.presenter.UpdateSchedulePresenter;
import com.liukai.todo_android.ui.adapter.DetailRecyclerViewAdapter;
import com.liukai.todo_android.ui.dialog.listener.ModifySuccessListener;
import com.wang.avi.AVLoadingIndicatorView;

/**
 * @author ：liukai
 * @date ：Created in 2021/8/13 5:36 下午
 * @description：新增待办的对话框
 * @modified By：
 * @version: $
 */
public class ItemDetailDialog {

    private ItemVo itemVo;
    private Context context;
    private final int layoutId = R.layout.dialog_detail_concentration;
    private View view;
    private AlertDialog dialog;
    private RecyclerView recyclerView;

    public ItemDetailDialog(Context context, ItemVo _itemVo) {
        this.context = context;
        this.itemVo = _itemVo;
        createDialog();
        initView();
        initDate();
        initAdapter();
    }

    private void initAdapter() {
        DetailRecyclerViewAdapter adapter = new DetailRecyclerViewAdapter(itemVo);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new DividerItemDecoration(context,DividerItemDecoration.VERTICAL));

    }

    private void initDate() {
//        etScheduleTitle.setText(itemVo.getTitle());
//        etScheduleDesc.setText(itemVo.getDescription());
    }


    private void initView() {
        recyclerView = view.findViewById(R.id.recycler_view);
    }

    /**
     * 创建新增对话框
     */
    private void createDialog() {
        view = View.inflate(context, layoutId, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        // 设置点击可取消
        builder.setCancelable(true);
        dialog = builder.create();
    }

    public void show() {
        dialog.show();
        // 获取Window对象
        Window window = dialog.getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        // 设置显示视图内容
        window.setContentView(view);
    }
}
